﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Utils.Menu;
using DevExpress.XtraGrid;
using DevExpress.XtraPivotGrid;

namespace RestaurantManagement.Controls
{
    public class BaseModule : XtraUserControl
    {
        internal bool FirstShowing = true;
        internal virtual void HideModule() { }

        public virtual string ModuleCaption { get { return string.Empty; } }
        public virtual string ModuleName { get { return ModuleCaption; } }

        internal virtual void ShowModule(object item)
        {
            FirstShowing = false;
        }

        internal virtual void InitModule(IDXMenuManager manager, object data)
        {
            SetMenuManager(this.Controls, manager);
        }

        void SetMenuManager(ControlCollection controlCollection, IDXMenuManager manager)
        {
            foreach (Control ctrl in controlCollection)
            {
                GridControl grid = ctrl as GridControl;
                if (grid != null)
                {
                    grid.MenuManager = manager;
                    break;
                }
                PivotGridControl pivot = ctrl as PivotGridControl;
                if (pivot != null)
                {
                    pivot.MenuManager = manager;
                    break;
                }
                BaseEdit edit = ctrl as BaseEdit;
                if (edit != null)
                {
                    edit.MenuManager = manager;
                    break;
                }
                SetMenuManager(ctrl.Controls, manager);
            }
        }
        public virtual bool AllowWaitDialog { get { return true; } }
    }
}
